Skip to content

Migrate to Spring Batch 6 #46216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

fmbenhassine
Copy link
Contributor

This PR upgrades Spring Boot 4 to Spring Batch 6.

Most of the changes are documented here: https://github.com/spring-projects/spring-batch/wiki/Spring-Batch-6.0-Migration-Guide

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 26, 2025
@philwebb philwebb added type: dependency-upgrade A dependency upgrade and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 26, 2025
@philwebb philwebb modified the milestone: 4.0.x Jun 26, 2025
@snicoll snicoll changed the title Upgrade Spring Batch to version 6 Migrate to Spring Batch 6 Jun 27, 2025
@snicoll snicoll added type: enhancement A general enhancement and removed type: dependency-upgrade A dependency upgrade labels Jun 27, 2025
@snicoll snicoll self-assigned this Jun 27, 2025
@snicoll snicoll modified the milestones: 4.0.x, 4.0.0-M1 Jun 27, 2025
Copy link
Member

@snicoll snicoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. There are a number of things we need to fix before going forward. I've added comments.

@@ -172,6 +172,7 @@ protected ExecutionContextSerializer getExecutionContextSerializer() {
: super.getExecutionContextSerializer();
}

@SuppressWarnings("removal")
Copy link
Member

@snicoll snicoll Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what to make of this. The method is deprecated but the class isn't. If we don't want this to be configurable going forward, I'd rather remove the override (and the ObjectProvider)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could still be configurable until the method is removed in Spring Batch 6.2. Maybe this configuration option should be documented as deprecated in Spring Boot docs? Wdyt?

import org.springframework.core.convert.support.ConfigurableConversionService;

/**
* Callback interface that can be implemented by beans wishing to customize the
* {@link ConfigurableConversionService} that is
* {@link DefaultBatchConfiguration#getConversionService provided by
* {@link JdbcDefaultBatchConfiguration#getConversionService provided by
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should relax the javadoc a bit. It looks weird that we refer to that method. Something like

Callback interface that can be implemented by beans wishing to customize the ConfigurableConversionService that is use by the batch infrastructure while retaining its default auto-configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

private JobParameters getNextJobParameters(Job job, JobParameters jobParameters) {
if (this.jobRepository != null && this.jobRepository.isJobInstanceExists(job.getName(), jobParameters)) {
if (this.jobRepository != null && this.jobRepository.getJobInstance(job.getName(), jobParameters) != null) {
Copy link
Member

@snicoll snicoll Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something should be adapted in Spring Batch here. JobRepository isn't deprecated but JobExplorer is. The former extends the latter so any method that is not specified in the child is flagged as deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spring Batch was updated. I have removed the @SuppressWarning("removed")

.getNextJobParameters(job)
.toJobParameters();
return merge(nextParameters, jobParameters);
}

@SuppressWarnings("deprecated")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I see what this suppresses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was meant to suppress the warning about the call of the deprecated method jobRepository.getLastJobExecution. But this is now fixed.

@@ -114,6 +107,7 @@
* @author Yanming Zhou
*/
@ExtendWith(OutputCaptureExtension.class)
@SuppressWarnings("removal")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the plan to deal with those deprecations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in Spring Batch.

// the following assertion should pass as taskExecutor is inherited from
// TaskExecutorJobLauncher
// assertThat(context.getBean(JobOperator.class)).hasFieldOrPropertyWithValue("taskExecutor",
// batchTaskExecutor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't comment code like that.

The assertion does not pass because context.getBean(JobOperator.class) returns a JDK Proxy. And that proxy does not have such field. We should figure out why it returns a proxy and it didn't before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the assertion.

@snicoll snicoll added the status: on-hold We can't start working on this issue yet label Jul 1, 2025
@snicoll
Copy link
Member

snicoll commented Jul 1, 2025

There a number of things that should happen in Spring Batch before we can make progress here, notably a status on JobParametersConverter (spring-projects/spring-batch#4894) and methods that are deprecated while they aren't (due to inheritance and the lack of an override in the interface that isn't deprecated).

- Fix deprecation warnings
- Fix assertion in BatchAutoConfigurationTests
- Update Javadocs
@fmbenhassine
Copy link
Contributor Author

Thanks for the review.

notably a status on JobParametersConverter (spring-projects/spring-batch#4894)

The deprecation was reverted.

methods that are deprecated while they aren't (due to inheritance and the lack of an override in the interface that isn't deprecated).

This was fixed in Spring Batch.

I will add some inline comments as well.

@snicoll snicoll removed the status: on-hold We can't start working on this issue yet label Jul 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants